<?php
ob_start();
session_start();
?>

<html>
<head>
</head>
<body>
<div align="center">

<?php
include ("connect.php");
$dbname = 'Transportation';
mysql_select_db($dbname);

$qq = "SELECT DISTINCT busroutes.busname
FROM busschedule, busroutes
WHERE busschedule.busid = '$_POST[mydropdown1]'
AND busschedule.busid = busroutes.busid";

$rr = mysql_query($qq);
$bus_name = mysql_fetch_array($rr);
$busname = $bus_name["busname"];

$page_title = "Abu Dhabi Transportation Website - Schedule for $_POST[mydropdown1] $busname";
$loginText = "Sign In";
$leftMenu = array
	(
		 "Home" => "index.php",
		"Routes" => "routes.php",
		"Schedule" => "Schedule.php",
		"Stops" => "Stops.php",
		"How To Go There" => "#",
	);

$q1 = "SELECT DISTINCT time
FROM busschedule, busstops, busroutes
WHERE busschedule.busid = '$_POST[mydropdown1]' AND busschedule.stopid = busstops.id 
AND busschedule.busid = busroutes.busid and busstops.name = busroutes.START"; 
$result1 = mysql_query($q1);

$q2= "SELECT DISTINCT time
from busschedule, busstops, busroutes
where busschedule.busid = '$_POST[mydropdown1]' and busschedule.stopid = busstops.id 
and busschedule.busid = busroutes.busid and busstops.name = busroutes.end";
$result2 = mysql_query($q2);

$r = "SELECT DISTINCT name
FROM busroutes, busschedule, busstops
WHERE busschedule.busid = '$_POST[mydropdown1]' AND busschedule.stopid = busstops.id 
AND busschedule.busid = busroutes.busid and busstops.name = busroutes.start";
$result_r = mysql_query($r);

$stop_first = mysql_fetch_array($result_r);
$stopname1 = $stop_first["name"];

$s = "SELECT DISTINCT name
FROM busroutes, busschedule, busstops
WHERE busschedule.busid = '$_POST[mydropdown1]' AND busschedule.stopid = busstops.id 
AND busschedule.busid = busroutes.busid and busstops.name = busroutes.end";
$result_s = mysql_query($s);

$stop_second = mysql_fetch_array($result_s);
$stopname2 = $stop_second["name"]; 

$content = '<table class = "data">';

$content .= "<caption> The Schedule for Bus Number $_POST[mydropdown1] <br/> $busname</caption>";

$content .= "<tr> <th> $stopname1 </th><th> $stopname2 </th> </tr>";

while (($row1 = mysql_fetch_array($result1)) && ($row2 = mysql_fetch_array($result2))) 
{
$content .= "<tr>
    <td class = 'spec'>$row1[time]</td>
    <td class = 'specalt'>$row2[time]</td>
   </tr>";
}

$content .= '</table>';

include("default_layout.php");
?>

</div>
</body>
</html>